<?php

require_once dirname(__FILE__).'/../lib/resumenGeneratorConfiguration.class.php';
require_once dirname(__FILE__).'/../lib/resumenGeneratorHelper.class.php';

/**
 * resumen actions.
 *
 * @package    odontopc
 * @subpackage resumen
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class resumenActions extends autoResumenActions
{
  public function executeListDetalle(sfWebRequest $request){
    $this->redirect( 'detres/index?rid='.$this->getRequestParameter('id'));
  }
  
  public function executeListFactura(sfWebRequest $request){
    $this->redirect( 'vta/index?rid='.$this->getRequestParameter('id'));
  }    
  
  public function executeListMail(sfWebRequest $request){
    $resumen = Doctrine::getTable('Resumen')->find($this->getRequestParameter('id'));
    
    $mensaje = Swift_Message::newInstance();
    $mensaje->setFrom(array('info@odontovta.net23.net' => 'NTI implantes'));
    $mensaje->setTo($resumen->getCliente()->getEmail());
    $mensaje->setSubject('Detalle Venta');
    $mensaje->setBody($this->getPartial("detres/imprimir", array("resumen" => $resumen)));
    $mensaje->setContentType("text/html");
    $this->getMailer()->send($mensaje);
    
    $this->getUser()->setFlash('notice', 'El mail se enviado correctamente a la direccion '.$resumen->getCliente()->getEmail());
    $this->redirect('resumen');    
  }
  
  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $notice = $form->getObject()->isNew() ? 'The item was created successfully.' : 'The item was updated successfully.';

      $resumen = $form->save();
      
      $this->redirect( 'detres/new?rid='.$resumen->getId());
    }
  }
  
  
  public function executeGuardarnuevocliente(sfWebRequest $request){
    $objProd = new Cliente();
    $datos = $request->getParameter('cliente');
    
    $objProd->setTipoId($datos['tipo_id']);
    $objProd->setDni($datos['dni']);
    $objProd->setCuit($datos['cuit']);
    $objProd->setCondicionfiscalId($datos['condicionfiscal_id']);
    $objProd->setGeneraComision($datos['genera_comision']);
    $objProd->setSexo($datos['sexo']);
    $objProd->setApellido($datos['apellido']);
    $objProd->setNombre($datos['nombre']);
    $objProd->setFechaNacimiento($datos['fecha_nacimiento']);
    $objProd->setDomicilio($datos['domicilio']);
    $objProd->setLocalidadId($datos['localidad_id']);
    $objProd->setTelefono($datos['telefono']);
    $objProd->setCelular($datos['celular']);
    $objProd->setFax($datos['fax']);
    $objProd->setEmail($datos['email']);
    $objProd->setObservacion($datos['observacion']);
    
    $objProd->save();
    
    return $this->renderText(json_encode($objProd->getId()));
  }    
}
